package bb.lanxing.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.baidu.mapapi.search.core.PoiInfo;
import bb.lanxing.R;
import java.util.ArrayList;
import java.util.List;

public class LocationSearchAdapter extends BaseAdapter {
    private Context context;
    private List<PoiInfo> poiInfoList;

    @Override
    public long getItemId(int position) {
        return position;
    }

    public LocationSearchAdapter() {
        this.poiInfoList = new ArrayList();
    }

    public LocationSearchAdapter(Context context, List<PoiInfo> poiInfoList) {
        new ArrayList();
        this.context = context;
        this.poiInfoList = poiInfoList;
    }

    @Override
    public Object getItem(int position) {
        return this.poiInfoList.get(position);
    }

    @Override
    public int getCount() {
        return this.poiInfoList.size();
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.location_search_list_item, parent, false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        PoiInfo poiInfo = this.poiInfoList.get(position);
        viewHolder.nameView.setText(poiInfo.name);
        viewHolder.addressView.setText(poiInfo.address);
        return convertView;
    }

    static class ViewHolder {
        TextView addressView;
        TextView nameView;

        ViewHolder(View view) {
            this.nameView = (TextView) view.findViewById(R.id.nameView);
            this.addressView = (TextView) view.findViewById(R.id.addressView);
        }
    }
}
